package tings;

import java.util.ArrayList;
import java.util.HashMap;

import maths.Runge;

import org.newdawn.slick.geom.Polygon;
import org.newdawn.slick.geom.Shape;
import org.newdawn.slick.geom.Transform;

import LBC.CollisionListener;
import Objects.Body;
import Objects.BodyCircle;
import Objects.BodyRectangle;


public class Moves extends Thread{

//	ArrayList<Shape> shapes;
	ArrayList<Shape> work;
//	HashMap<Shape, Body> stb;
//	HashMap<Shape, BodyRectangle> str;
//	HashMap<Shape, BodyCircle> stc;
	@SuppressWarnings("unchecked")
	public HashMap []hM;
	public HashMap<Integer, Body> bodies;
    public HashMap<Body, BodyRectangle> btr;
    public HashMap<Body, BodyCircle> btc;
	Shape s;
	Body b;
	BodyRectangle r1;
	BodyCircle c1;
	CollisionListener listener;
	float []points;
	float time;
	float VXmax;
	float VYmax;
	Runge runge;
	
	@SuppressWarnings("unchecked")
	public Moves(HashMap []hM, Integer time){
//		this.shapes=shapes;
//		this.stb=stb;
//		this.str=str;
//		this.stc=stc;
		this.hM=hM;
	    bodies=hM[0];
	    btr=hM[1];
	    btc=hM[2];
		this.time=time;
		runge=new Runge(bodies,time);
	}


//	OLD MOVES
//	public void move(){
//		for (int i=0 ; i<shapes.size() ; i++){
//			if(str.get(shapes.get(i)) != null){
//				stb.get(shapes.get(i)).angle+=stb.get(shapes.get(i)).angularVelocity;
//				str.get(shapes.get(i)).polygon=(Polygon) str.get(shapes.get(i)).polygon.transform(Transform.createRotateTransform(stb.get(shapes.get(i)).angle, stb.get(shapes.get(i)).shape.getCenterX(), stb.get(shapes.get(i)).shape.getCenterY()));
//				stb.get(shapes.get(i)).shape=str.get(shapes.get(i)).polygon;
//			}
//			stb.get(shapes.get(i)).velocityX+=stb.get(shapes.get(i)).forceX/stb.get(shapes.get(i)).mass;
//			stb.get(shapes.get(i)).velocityY+=stb.get(shapes.get(i)).forceY/stb.get(shapes.get(i)).mass;
//			stb.get(shapes.get(i)).shape.setCenterX(stb.get(shapes.get(i)).shape.getCenterX()+stb.get(shapes.get(i)).velocityX);
//			stb.get(shapes.get(i)).shape.setCenterY(stb.get(shapes.get(i)).shape.getCenterY()+stb.get(shapes.get(i)).velocityY);
//		}
//
//	}
	public void move(){
		//System.out.println(time);
		for (int i=0 ; i<bodies.size() ; i++){
			runge.compute((bodies.get(i)),bodies.get(i).colx-bodies.get(i).shape.getCenterX(),bodies.get(i).coly-bodies.get(i).shape.getCenterY());
			//runge.compute(stb.get(shapes.get(i)),0,0);
				if(btr.get(bodies.get(i)) != null){
					//stb.get(shapes.get(i)).angle+=stb.get(shapes.get(i)).angularVelocity;
					btr.get(bodies.get(i)).polygon=(Polygon) btr.get(bodies.get(i)).polygon.transform(Transform.createRotateTransform(bodies.get(i).angle, bodies.get(i).shape.getCenterX(), bodies.get(i).shape.getCenterY()));
					bodies.get(i).shape=btr.get(bodies.get(i)).polygon;
				}
				bodies.get(i).resetColXY();
		}
	}
}